let token = sessionStorage.getItem("token");
let user_id = sessionStorage.getItem("user_id");
$(function () {
    $("#name").html(sessionStorage.getItem("username"));
    //页数
    let pages =1;
    //筛选未审核列表
    let status ="";
    $("#wait").click(function () {
            status = "0";
            loadData(1);
    });
    //筛选全部列表
    $("#all").click(function () {
        status = "";
        loadData(1);
    });
    //筛选通过拒绝列表
    $("#done").click(function () {
        status = "1,2";
        loadData(1);
    });
    function loadData(pageNum){
        $.ajax({
            url:testurl + "meeting/leave/list_p",
            type:"post",
            headers: { "Authorization": "Bearer " + token},
            contentType: "application/json",
            data:JSON.stringify({
                "pageNum": pageNum,
                "user_id":user_id,
                "status":status
            }),
            success: function (data) {
                let yianmessage = data.obj;
                ssd = Math.ceil(data.pageTotal/data.pageSize);
                pages = ssd;
                str = "";
                $.each(yianmessage ,function (index,values) {
                    str += " <tr class=\"gradeX\">\n" +
                        "                                        <td>"+(index+1)+"</td>\n" +
                        "                                        <td>"+values.meeting_name
                                                                        +"</td>\n" +
                        "                                        <td>"+values.meeting_times+"</td>\n" +
                        "                                        <td>"+values.realname+"</td>\n" +
                        "                                        <td>"+values.cause+"</td>\n" +
                        "                                        <td class='textColor'>"+values.status_name+"</td>\n" +
                        "                                        <td>\n" +
                        "                                            <div class=\"tpl-table-black-operation\">\n" +
                        "                                                <a onclick=\"getMeetingLeave('"+values.id+','+values.check_flag+"')\" data-am-modal=\"{target:'#leaveDetail'}\"  href=\"#\" class=\"tpl-table-black-operation\">\n" +
                        "                                                    <i class=\"am-icon-check\"></i> 查看审批\n" +
                        "                                                </a>\n"+
                        "                                            </div>\n" +
                        "                                        </td>\n" +
                        "                                    </tr>";
                });
                $("#show").html(str);
            }
        });
    }
    loadData(1);

    //分页
    let pageNum = 1;
    $(".first").click(function(){
        pageNum =1;
        loadData(pageNum);
        $(this).parents("li").addClass("am-active");
        $(this).parents("li").siblings().removeClass("am-active");
    });
    $(".last").click(function(){
        pageNum = pages;
        loadData(pageNum);
        $(this).parents("li").addClass("am-active");
        $(this).parents("li").siblings().removeClass("am-active");
    });
    $(".up").click(function(){
        if(pageNum === 1){
            return false;
        } else{
            pageNum--;
            loadData(pageNum);
        }
        $(this).parents("li").addClass("am-active");
        $(this).parents("li").siblings().removeClass("am-active");
    });
    $(".down").click(function(){
        if(pageNum === pages){
            return false;
        } else{
            pageNum++;
            loadData(pageNum);
        }
        $(this).parents("li").addClass("am-active");
        $(this).parents("li").siblings().removeClass("am-active");
    });
});
function getMeetingLeave(e,f) {
    $.ajax({
        url:testurl + "meeting/leave/detail",
        type:"post",
        headers: { "Authorization": "Bearer " + token},
        contentType: "application/json",
        data:JSON.stringify({
                "id":e
        }),
        success: function (data) {
            $("#meetingName").html(data.obj.meeting_name);
            $("#applyTime").html(data.obj.leave_times);
            $("#realName").html(data.obj.realname);
            $("#cause").html(data.obj.cause);
            if (f === "0"){
            $("#remark").parent("li").css("display","none");
            } else {
                $("#remark").html(data.obj.remark);
            }
        }
    });

}